/**
 * Copyright (C), 2016-2019
 * FileName: UserController
 * Author:   yacnog_liu
 * Date:     2019/4/5 16:45
 * Description:
 */
package com.mayi.bootdemo.controller;

import com.mayi.bootdemo.pojo.User;
import com.mayi.bootdemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/addUser")
    public String insertUser(String name, Integer age) {
        User user = new User(name, age);
        this.userService.insertUser(user);
        return user.toString();

    }

    @RequestMapping("/findAll")
    public Map<String, Object> findAllUser() {
        Map<String, Object> map = new HashMap<String, Object>(1);
        List<User> allUser = this.userService.findAllUser();
        map.put("list", allUser);
        return map;
    }
}
